package com.youhome.service.service.impl;

import com.youhome.common.exception.CustomException;
import com.youhome.common.response.Result;
import com.youhome.common.response.ResultCode;
import com.youhome.service.mapper.BTemplateMailMapper;
import com.youhome.service.model.BTemplateMail;
import com.youhome.service.service.BTemplateMailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * Created by chen365 on 2017/12/20.
 */
@Service
public class BTemplateMailServiceImpl implements BTemplateMailService {

    @Autowired
    private BTemplateMailMapper bTemplateMailMapper;

    @Override
    public List<BTemplateMail> selectByBean(BTemplateMail record) {
        return bTemplateMailMapper.selectByBean(record);
    }

    @Override
    public BTemplateMail selectByPrimaryKey(Long id) throws CustomException {
        if (StringUtils.isEmpty(id)) {
            throw new CustomException(ResultCode.ERROR_PARAMETER);
        }
        return bTemplateMailMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<BTemplateMail> selectMailTemplate(Integer type) throws CustomException {
        BTemplateMail bTemplateMail = new BTemplateMail();
        bTemplateMail.setStatus(true);
        if (!StringUtils.isEmpty(type)) {
            bTemplateMail.setType(type);
        }
        return bTemplateMailMapper.selectByBean(bTemplateMail);
    }
}
